home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / disk-tools / misc / floppy / setboot.s < prev    next >
Text File  |  1996-02-26  |  5KB  |  136 lines

  1. *****************************************************************************
  2. *          SET BOOT CODE                                                    *
  3. * Compiler: Devpac 3.04                                              ORHAN  *
  4. *****************************************************************************
  5.            MACHINE     MC68000
  6.            INCLUDE     "exec/types.i"
  7.            INCLUDE     "exec/resident.i"
  8.            INCLUDE     "libraries/expansionbase.i"
  9.            INCLUDE     "lvo/exec_lib.i"
  10.            XDEF        _SetBoot
  11.            XDEF        _ClrBoot
  12.            XDEF        _BootChkSum
  13.            XDEF        _EvalChkSum
  14. *****************************************************************************
  15. *  arg1= bootblock adr, arg2= length, arg3= rootblock, ret= 0 if succesful  *
  16. *****************************************************************************
  17.            SECTION     "CODE",CODE
  18. _SetBoot:
  19.            LEA.L       4(SP),A0          ;arg ptr
  20.            MOVEM.L     D2/A2,-(SP)
  21.            MOVE.L      0(A0),A2          ;get bootblock adr
  22.            MOVE.L      4(A0),D2          ;get length
  23.            MOVE.L      8(A0),D1          ;get rootblock
  24.  
  25.            CMP.L       #LENBOOT+12,D2
  26.            BLO         ERROR
  27.  
  28.            MOVE.L      D1,8(A2)          ;set rootblock
  29.  
  30.            LEA.L       12(A2),A0
  31.            MOVE.L      D2,D0
  32.            LSR.L       #2,D0
  33.            SUB.L       #3+1,D0
  34. AA7:       CLR.L       (A0)+             ;clear bootblock
  35.            DBF         D0,AA7
  36.  
  37.            LEA.L       BOOTCODE,A0
  38.            LEA.L       12(A2),A1
  39.            MOVE.L      #LENBOOT-1,D0
  40. AA2:       MOVE.B      (A0)+,(A1)+       ;copy boot code
  41.            DBF         D0,AA2
  42.  
  43.            MOVE.L      D2,-(SP)
  44.            MOVE.L      A2,-(SP)
  45.            BSR         _EvalChkSum
  46.            ADD.L       #8,SP
  47.            MOVE.L      #0,D0
  48. EXIT:
  49.            MOVEM.L     (SP)+,D2/A2
  50.            RTS
  51. ERROR:     MOVE.L      #-1,D0
  52.            BRA         EXIT
  53. *****************************************************************************
  54. *          clear bootblock                                                  *
  55. *    arg1= boot block adr,  arg2= length                                    *
  56. *****************************************************************************
  57. _ClrBoot:
  58.            MOVE.L      4(SP),A0          ;get boot block adr
  59.            MOVE.L      8(SP),D0          ;get length
  60.  
  61.            LEA.L       4(A0),A0
  62.            LSR.L       #2,D0
  63.            SUB.L       #1+1,D0
  64. AA5:       CLR.L       (A0)+
  65.            DBF         D0,AA5
  66.            RTS
  67. *****************************************************************************
  68. *          checks bootblock checksum                                        *
  69. *    arg1= bootblock adr,  arg2= length,  ret= 0 if successful              *
  70. *****************************************************************************
  71. _BootChkSum:
  72.            MOVE.L      4(SP),A0          ;get bootblock adr
  73.            MOVE.L      8(SP),D1          ;get length
  74.  
  75.            CLR.L       D0
  76.            LSR.L       #2,D1
  77.            SUB.L       #1,D1
  78. AA4:       ADD.L       (A0)+,D0
  79.            BCC.S       AA3
  80.            ADD.L       #1,D0
  81. AA3:       DBF         D1,AA4
  82.            NOT.L       D0
  83.            RTS
  84. *****************************************************************************
  85. *          calculate bootblock checksum and update it                       *
  86. *    arg1= bootblock adr,  arg2= length                                     *
  87. *****************************************************************************
  88. _EvalChkSum:
  89.            MOVE.L      4(SP),A0          ;get bootblock adr
  90.            MOVE.L      8(SP),D0          ;get length
  91.  
  92.            LEA.L       4(A0),A1
  93.            CLR.L       (A1)
  94.            CLR.L       D1
  95.            LSR.L       #2,D0
  96.            SUB.L       #1,D0
  97. AA6:       ADD.L       (A0)+,D1
  98.            BCC.S       AA1
  99.            ADD.L       #1,D1
  100. AA1:       DBF         D0,AA6
  101.            NOT.L       D1
  102.            MOVE.L      D1,(A1) 
  103.            RTS
  104. *****************************************************************************
  105. *          STANDARD BOOT CODE   (KICKSTART R2.0-R3.0)                       *
  106. *****************************************************************************
  107. BOOTCODE:
  108.            LEA.L       EXPNAME(PC),A1
  109.            MOVEQ.L     #37,D0
  110.            CALLSYS     OpenLibrary
  111.            TST.L       D0
  112.            BEQ.W       AA0
  113.  
  114.            MOVE.L      D0,A1
  115.            BSET.B      #EBB_SILENTSTART,eb_Flags(A1)
  116.            CALLSYS     CloseLibrary
  117. AA0:
  118.            LEA.L       DOSNAME(PC),A1
  119.            CALLSYS     FindResident
  120.            TST.L       D0
  121.            BEQ.W       EXITSYS2
  122.  
  123.            MOVE.L      D0,A0
  124.            MOVE.L      RT_INIT(A0),A0
  125. EXITSYS:
  126.            MOVEQ.L     #0,D0
  127.            RTS
  128. EXITSYS2:
  129.            MOVEQ.L     #-1,D0
  130.            RTS
  131.  
  132. DOSNAME    DC.B        'dos.library',0
  133. EXPNAME    DC.B        'expansion.library',0
  134. LENBOOT    EQU         *-BOOTCODE
  135.            END
  136.